package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.util.FormulaUtil
import com.yc.yclibrary.base.YcAppCompatActivity
import kotlinx.android.synthetic.main.formula_button.*
import kotlinx.android.synthetic.main.type2_formula3_location_activity.*

/**
 * 声学 - 已知频率求时间
 */
class Type2Formula3Activity : BaseActivity() {

    companion object {
        private const val KEY_TITLE = "key_title"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, title: String) {
            val intent = Intent(activity, Type2Formula3Activity::class.java)
            intent.putExtra(KEY_TITLE, title)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type2_formula3_location_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        setActionBar(intent.getStringExtra(KEY_TITLE))
        formulaResetBtn.setOnClickListener {
            formula4_f_TEV.reset()
            formula4_t1_TEV.reset()
            formula4_t2_TEV.reset()
            formula4_t3_TEV.reset()
            formula4_t4_TEV.reset()
            formula4_t5_TEV.reset()
            formula4_bc1_TEV.reset()
            formula4_bc2_TEV.reset()
            formula4_bc3_TEV.reset()
            formula4_bc4_TEV.reset()
            formula4_bc5_TEV.reset()
        }
        formulaOkBtn.setOnClickListener {
            try {
                formula4_t1_TEV.setText(
                    FormulaUtil.formula2_3_1(
                        formula4_f_TEV.getDouble(),
                        1.0
                    )
                )
                formula4_t2_TEV.setText(
                    FormulaUtil.formula2_3_1(
                        formula4_f_TEV.getDouble(),
                        1.0 / 3
                    )
                )
                formula4_t3_TEV.setText(
                    FormulaUtil.formula2_3_1(
                        formula4_f_TEV.getDouble(),
                        1.0 / 2
                    )
                )
                formula4_t4_TEV.setText(
                    FormulaUtil.formula2_3_1(
                        formula4_f_TEV.getDouble(),
                        2.0 / 3
                    )
                )
                formula4_t5_TEV.setText(
                    FormulaUtil.formula2_3_1(
                        formula4_f_TEV.getDouble(),
                        3.0 / 2
                    )
                )


                formula4_bc1_TEV.setText(
                    FormulaUtil.formula2_3_2(
                        formula4_f_TEV.getDouble(),
                        1.0
                    )
                )
                formula4_bc2_TEV.setText(
                    FormulaUtil.formula2_3_2(
                        formula4_f_TEV.getDouble(),
                        1.0 / 3
                    )
                )
                formula4_bc3_TEV.setText(
                    FormulaUtil.formula2_3_2(
                        formula4_f_TEV.getDouble(),
                        1.0 / 2
                    )
                )
                formula4_bc4_TEV.setText(
                    FormulaUtil.formula2_3_2(
                        formula4_f_TEV.getDouble(),
                        2.0 / 3
                    )
                )
                formula4_bc5_TEV.setText(
                    FormulaUtil.formula2_3_2(
                        formula4_f_TEV.getDouble(),
                        3.0 / 2
                    )
                )
            } catch (e: NumberFormatException) {
                formula4_t1_TEV.setText("Infinity")
                formula4_t2_TEV.setText("Infinity")
                formula4_t3_TEV.setText("Infinity")
                formula4_t4_TEV.setText("Infinity")
                formula4_t5_TEV.setText("Infinity")
                formula4_bc1_TEV.setText("Infinity")
                formula4_bc2_TEV.setText("Infinity")
                formula4_bc3_TEV.setText("Infinity")
                formula4_bc4_TEV.setText("Infinity")
                formula4_bc5_TEV.setText("Infinity")
            }
        }
    }
}